package im.vinci.server.music.controller;

import im.vinci.server.music.domain.MusicStyle;
import im.vinci.server.music.service.MusicalPreferenceService;
import im.vinci.server.security.ApiSecurityLabel;
import im.vinci.server.utils.UserContext;
import im.vinci.server.utils.apiresp.Result;
import im.vinci.server.utils.apiresp.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * Created by mingjie on 17/3/11.
 */
@RestController
@RequestMapping(value = "/vinci/user/music/preference", produces = "application/json;charset=UTF-8")
public class MusicalPreferenceController {

    @Autowired
    private MusicalPreferenceService musicalPreferenceService;

    @RequestMapping(value = "/default", method = RequestMethod.GET)
    @ApiSecurityLabel(isCheckLogin = true)
    public ResultObject<List<MusicStyle>> getMusicStyleData() {
        List<MusicStyle> list = musicalPreferenceService.getMusicStyleData();
        return new ResultObject<>(list);
    }

    @RequestMapping(method = RequestMethod.POST)
    @ApiSecurityLabel(isCheckLogin = true)
    public Result postPreferences(@RequestBody List<MusicStyle> dataList) {
        musicalPreferenceService.postMusicPreference(dataList);
        return new Result();
    }

    @RequestMapping(method = RequestMethod.GET)
    @ApiSecurityLabel(isCheckLogin = true)
    public ResultObject<List<MusicStyle>> getPreferences() {
        return new ResultObject<>(musicalPreferenceService.getMusicPreference(UserContext.getUserInfo().getId()));
    }
}
